/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ThreadHandle {

    private final List<Clients> threads;

    public List<Clients> getthreads() {
        return threads;
    }

    public ThreadHandle() {
        threads = new ArrayList<>();
    }

    public void AddThread(Clients client) {
        int i = 0;
        for (Clients client1 : threads) {
            if (!(client1.getthread().getName().equals(client.getthread().getName()))) {
                i++;
            }
        }
        if (i == (threads.size())) {
            threads.add(client);
        }
    }

    public void RemoveThread(Clients client) {
        for (Iterator<Clients> it = threads.iterator(); it.hasNext();) {
            Clients client1 = it.next();
            if (client1.getthread().getName().equals(client.getthread().getName())) {
                it.remove();
            }
        }
    }

    public void Empty() {
        for (Iterator<Clients> it = threads.iterator(); it.hasNext();) {
            //Clients client1 = it.next();
            it.remove();
        }
    }
}
